﻿using System.Net.Http;

namespace Sidvall.Net
{
    public static class HttpManager
    {
        #region CreateResponseMessage

        internal static HttpResponse CreateResponseMessage(HttpResponseMessage responseMessage)
        {
            var statusCode = responseMessage.StatusCode;
            var reasonPhrase = responseMessage.ReasonPhrase;
            if (statusCode == System.Net.HttpStatusCode.UnsupportedMediaType)
            {
                statusCode = System.Net.HttpStatusCode.Unauthorized;
                reasonPhrase = "Unauthorized-UnsupportedMediaType";
            }
            return new HttpResponse()
            {
                Content = new HttpContent()
                {
                    Content = responseMessage.Content,
                },
                Headers = new HttpResponseHeaders()
                {
                    Location = responseMessage.Headers.Location,
                },
                ReasonPhrase = reasonPhrase,
                StatusCode = statusCode,
            };
        }

        #endregion
    }
}
